#include "zhuce.h"
#include "ui_zhuce.h"

zhuce::zhuce(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::zhuce)
{
    ui->setupUi(this);
    TCP = NULL;
    message = NULL;
}

zhuce::~zhuce()
{
    delete ui;
}
//返回主界面函数
void zhuce::on_fanhuijiemian_pushButton_clicked()
{
    emit zhujiemianxianshi();
}
//按下按钮将注册信息发送到server,将判断返回信息
void zhuce::on_tijioachucexinxi_pushButton_clicked()
{
//入参检测
if(ui->zhucemima_lineEdit->text() == NULL || ui->zhucemingzi_lineEdit->text() == NULL ||
        ui->zhucenianling_lineEdit->text() == NULL){
    QMessageBox::warning(this,"error","Please enter you message");
}else{
//获取消息
         message->flags = ZHUCE;
         message->age = ui->zhucenianling_lineEdit->text().toInt();
         strcpy(message->name,ui->zhucemingzi_lineEdit->text().toLatin1().data());
          message->passwd = ui->zhucemima_lineEdit->text().toInt();
//发送消息
         this->TCP->write((char *)message,(quint64)sizeof(messageText));
              if(message->ret == NO){
              QMessageBox::warning(this,"error","Fa Song Shu Ju Shi Bai");
          }else{
//接受消息
              QMessageBox::information(this,"OK","Register OK,Please rember you id and passwd");
              ui->fanhuiID_lineEdit->setText(QString::number(this->message->id));
           }
       }

}
//获取传输条件
void zhuce::needMessageAndSocket(messageText *messa,QTcpSocket *socket){

    this->TCP = socket;
    this->message = messa;
}
